#ifndef RECORDDATAHELPER_H
#define RECORDDATAHELPER_H

#include <QDate>
#include <QDebug>
#include <QFile>
#include <QStringList>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QTextStream>
#include <QVariantMap>
#include <QVector>

// 记录类型枚举
enum class RecordType {
    DeviceData = 1,         // 设备数据记录
    UploadData = 2,         // 上传记录
    ErrorData = 3,          // 错误记录
    CalibrationData = 4,    // 校准记录
    InspectionData = 5,     // 核查记录
    SpikeRecoveryData = 6,  // 加标回收记录
};

class RecordDataHelper
{
public:
    // 核心功能方法
    static void setupTableHeaders(QTableWidget *tableWidget, RecordType recordType);
    static void loadPageData(QTableWidget *tableWidget, RecordType recordType, int currentPage,
                             int pageSize, const QDate &queryDate,
                             const QString &deviceName = QString());
    static int getTotalRecords(RecordType recordType, const QDate &queryDate,
                               const QString &deviceName = QString());

    // 数据导出功能
    static bool exportToCSV(const QString &filePath, RecordType recordType, const QDate &queryDate,
                            const QString &deviceName = QString());

private:
    // 设备数据相关方法
    static void setupDeviceDataHeaders(QTableWidget *tableWidget);
    static void loadDeviceData(QTableWidget *tableWidget, int currentPage, int pageSize,
                               const QDate &queryDate);

    // 上传记录相关方法
    static void setupUploadRecordHeaders(QTableWidget *tableWidget);
    static void loadUploadRecordData(QTableWidget *tableWidget, int currentPage, int pageSize,
                                     const QDate &queryDate);

    // 错误记录相关方法
    static void setupErrorLogHeaders(QTableWidget *tableWidget);
    static void loadErrorLogData(QTableWidget *tableWidget, int currentPage, int pageSize,
                                 const QDate &queryDate, const QString &deviceName = QString());

    // 校准记录相关方法
    static void setupCalibrationHeaders(QTableWidget *tableWidget);
    static void loadCalibrationData(QTableWidget *tableWidget, int currentPage, int pageSize,
                                    const QDate &queryDate, const QString &deviceName = QString());

    // 核查记录相关方法
    static void setupInspectionHeaders(QTableWidget *tableWidget);
    static void loadInspectionData(QTableWidget *tableWidget, int currentPage, int pageSize,
                                   const QDate &queryDate, const QString &deviceName = QString());

    // 加标回收记录相关方法
    static void setupSpikeRecoveryHeaders(QTableWidget *tableWidget);
    static void loadSpikeRecoveryData(QTableWidget *tableWidget, int currentPage, int pageSize,
                                      const QDate &queryDate,
                                      const QString &deviceName = QString());

    // CSV导出相关方法
    static bool exportDeviceDataToCSV(QTextStream &out, const QDate &queryDate,
                                      const QStringList &headers);
    static bool exportUploadDataToCSV(QTextStream &out, const QDate &queryDate,
                                      const QStringList &headers);
    static bool exportErrorDataToCSV(QTextStream &out, const QDate &queryDate,
                                     const QString &deviceName, const QStringList &headers);
    static bool exportCalibrationDataToCSV(QTextStream &out, const QDate &queryDate,
                                           const QString &deviceName, const QStringList &headers);
    static bool exportInspectionDataToCSV(QTextStream &out, const QDate &queryDate,
                                          const QString &deviceName, const QStringList &headers);
    static bool exportSpikeRecoveryDataToCSV(QTextStream &out, const QDate &queryDate,
                                             const QString &deviceName, const QStringList &headers);

    // 禁止实例化
    RecordDataHelper() = delete;
    ~RecordDataHelper() = delete;
    RecordDataHelper(const RecordDataHelper &) = delete;
    RecordDataHelper &operator=(const RecordDataHelper &) = delete;
};

#endif  // RECORDDATAHELPER_H